<?php
class ControllerAccountReward extends AccountController {
	public function index() {
				
      	$this->data['breadcrumbs'][] = array(       	
        	'text'      => $this->_['text_reward'],
			'href'      => U('account/reward', '', 'SSL'),
        	'separator' => $this->_['text_separator']
      	);
		
		M('account/reward');

		$page = (int) $this->request->get('page', 1);		
		
		$this->data['rewards'] = array();
		
		$data = array(				  
			'sort'  => 'date_added',
			'order' => 'DESC',
			'start' => ($page - 1) * 10,
			'limit' => 10
		);
		
		$reward_total = $this->model_account_reward->getTotalRewards($data);
	
		$results = $this->model_account_reward->getRewards($data);
 		
    	foreach ($results as $result) {
			$this->data['rewards'][] = array(
				'order_id'    => $result['order_id'],
				'points'      => $result['points'],
				'description' => $result['description'],
				'date_added'  => v5_date_format($result['date_added']),
				'href'        => US('account/order/info', 'order_id=' . $result['order_id'])
			);
		}	
			
		$this->data['pagination'] = $this->pagination($reward_total, $page, null, 10)->render();
		
		$this->data['total'] = $this->customer->getRewardPoints();
				
		$this->display('account/reward.tpl');
	} 		
}
?>